package com.example.demo.listening;

import com.example.demo.task.service.TaskSchedulerService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

/**
 * 启动时加载数据库定时任务，初始化定时任务
 * @Auther Created by l.wang on 2018/12/26.
 */
@Component
public class ApplicationListening implements ApplicationListener<ContextRefreshedEvent> {
    private final Log logger = LogFactory.getLog(getClass());
    @Autowired
    private TaskSchedulerService taskSchedulerService;

    @Override
    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
        //启动加载数据库，将任务状态为启动的加载至任务池中
        new Thread(()-> {
            logger.info("初始化定时任务");
            //        taskService.startCron("", "", "", "");
        }).start();
    }
}
